var Home=({
	queryHouseList:function(){
		var search = $("#search").val();
		$.ajax({
			type : "POST",
			dataType : 'json',
			url :  "../house/queryHouseList.do",
			data : {
				"search":search
			},
			success : function(data) {
				var html ="";
				console.log(data);
				if(data.rows.length>0){
					$(data.rows).each(function(i,n){
						var titlepic="";
						if(n.imglist !=null && n.imglist.length>0){
							for(var i=0;i<n.imglist.length;i++){
								if(n.imglist[i].type=='1'){
									titlepic=n.imglist[i].imgUrl
								}
							}
						}
					html+="<li id='"+n.house.houseId+"'>"+
					"<img class='tuijian_house_content_img' src='"+titlepic+"'>"+
					"<div class='house_title tit_top' style='    padding-left: 120px;'>"+((n.house.houseName.length>13)?(n.house.houseName.substring(0,13)+"..."):(n.house.houseName))+"</div>"+
					"<div class='house_title house_price' style='    padding-left: 120px;'><span class='house_size'>"+n.house.houseSize+"平方</span><span class='house_type'>"+(n.house.houseLayout==undefined?"暂无房型":n.house.houseLayout)+"</span><span class='price' style='    float: right;    margin-right: 25px;   '>"+n.house.price+"元/月</span><span class='status' style='position: absolute;font-size: 15px;top:32px;right:20px'>"+((n.house.status==2)?"已出租":"")+"</span></div>"+
						"<div class='house_title house_address' style='    padding-left: 120px;'><span class='jiaotong'><img src='../images/postion.png' class='position'>"+(n.house.specialNote ==null?"":(n.house.specialNote.length>15?(n.house.specialNote.substring(0,15)+"..."):n.house.specialNote))+"</span> </div></li>";
					
					})
					$(".house_ul").append(html);
					 $$.hidePreloader();
				}else{
					$$.toast("加载完毕");
					offset = 0;
					if($(".house_ul").children().length==0){
						$(".house_ul").html("<li  style=\'text-align:center;background: #f8f8f8;\'><img src=\"../images/nondata.png\"></li><li style=\'text-align:center;background: #f8f8f8;\'>暂无数据</li>");
					}
					 $$.hidePreloader();
				}
			}
		});
	},
	queryGoodHouseList:function(){
		$.ajax({
			type : "POST",
			dataType : 'json',
			url :"../house/queryHouseList.do",
			data : {
				"offset": 0,
				"limit": 5,
				"grade":1,
				"orderBy":"h.createTime desc",
			},
			success : function(data) {
				console.log(data)
				var html ="";
				if(data.rows.length>0){
					$(data.rows).each(function(i,n){
						var titlepic="";
						if(n.imglist !=null && n.imglist.length>0){
							for(var i=0;i<n.imglist.length;i++){
								if(n.imglist[i].type=='1'){
									titlepic=n.imglist[i].imgUrl
								}
							}
						}
					html+="<li id='"+n.house.houseId+"' style='position: relative;'>"+
					"<img class='tuijian_house_content_img' src='"+titlepic+"'>"+
					"<div class='house_title tit_top' style='    padding-left: 31%;'>"+((n.house.houseName.length>13)?(n.house.houseName.substring(0,13)+"..."):(n.house.houseName))+"</div>"+
					"<div class='house_title house_price' style='    padding-left: 31%;'><span class='house_size'>"+n.house.houseSize+"平方</span><span class='house_type'>"+(n.house.houseLayout==undefined?"暂无房型":n.house.houseLayout)+"</span><span class='price' style='    float: right;     margin-top: 2px;'>"+n.house.price+"元/月</span><span class='status' style='position: absolute;font-size: 15px;top:32px;right:20px'>"+((n.house.status==2)?"已出租":"")+"</span></div>"+
						"<div class='house_title house_address' style='    padding-left: 31%;'><span class='jiaotong'><img src='../images/postion.png' class='position'>"+(n.house.specialNote ==null?"":(n.house.specialNote.length>15?(n.house.specialNote.substring(0,15)+"..."):n.house.specialNote))+"</span> </div></li>";
					})
					$(".ghouse").append(html);
				}else{
					$$.toast("加载完毕");
					offset = 0;
					if($(".ghouse").children().length==0){
						$(".ghouse").html("<li  style=\'text-align:center;background: #f8f8f8;\'><img src=\"../images/nondata.png\"></li><li style=\'text-align:center;background: #f8f8f8;\'>暂无数据</li>");
					}
				}
			}
		});
	},
	tosearch : function (){
   	 $("#search_content").show();
   	 $("#container").hide();
    },
	back : function (){
   	 $("#search_content").hide();
   	 $("#container").show();
    },
    search : function  (){
    $$.showPreloader();
   	$(".house_ul").html("");
   	Home.queryHouseList();
    },
    toLink : function (txt,tagrt) {
		document.location.href = "./" + txt;
	}
});
$(function(){
  	window.$$=window.Zepto = Zepto;
	$('.flicker-example').flickerplate({
        auto_flick 				: true,
        auto_flick_delay 		: 8,
        flick_animation 		: 'transform-slide'
    });
	
	$("#rent ul li").click(function(){
		if($(this).index() == 3){
			$$.toast("功能努力上架中");
		}else{
			location.href = "lanjuZhengzu.html?type="+url[$(this).index()];
		}
	})
	
	$("#service ul li").click(function(){
		if($(this).index() == 0){
			location.href = "service/servicePackage.html?serviceType=1";//保洁服务
		}else if($(this).index() == 3){
			location.href = "service/serviceList.html?serviceType=1";//服务查询
		}else{
			$$.toast("功能努力上架中");
		}
	})
	
	$("#loadmore").click(function(){
		location.href = "lanjuZhengzu.html?type=2";
	})
	Home.queryGoodHouseList();
	$(".ghouse").on("click","li",function(){
		var houseId  = $(this).attr("id");
		window.location.href="../jsp/houseDetails.html?houseId="+houseId;
	})
	
	$(".house_ul").on("click","li",function(){
		var houseId  = $(this).attr("id");
		window.location.href="../jsp/houseDetails.html?houseId="+houseId;
	})
	$("#cancle").on("click",function(){
		$("#search_content").hide();
	   	 $("#container").show();
	   	 $("#search").val("");
	   	$(".house_ul").html("");
	})
});
